package com.tanhua.dubbo.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    /*登陆时通过手机号查询用户*/
    @Override
    public User findByMobile(String mobile) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("mobile",mobile);
        return userMapper.selectOne(qw);
    }

    /*首次登录 - 创建新用户*/
    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    /*更新用户环信信息*/
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    /*查询用户环信账号信息*/
    @Override
    public User findById(Long userId) {
        User user = userMapper.selectById(userId);
        return user;
    }

    /*环信用户ID查询用户信息*/
    @Override
    public User findByHuanXinId(String huanXinId) {
        QueryWrapper<User> qw=new QueryWrapper<>();
        qw.eq("hx_user",huanXinId);
        return userMapper.selectOne(qw);
    }

    /*修改用户手机号*/
    @Override
    public void updatePhone(User user) {
        userMapper.updateById(user);

    }
}
